package 链表.单链表;


/**
 * https://leetcode.cn/problems/linked-list-cycle/description/?envType=study-plan-v2&envId=top-100-liked
 *
 * https://mp.weixin.qq.com/s?__biz=MzAxODQxMDM0Mw==&mid=2247493145&idx=1&sn=b0912a4812e0c0129a009bca7fe94639&chksm=9bd41811aca391077e0ff2ca82e21ea05126b81513f1bb817866436dccdd81a2538d337cc00f&scene=178&cur_album_id=2165022824317485057#rd
 */
public class _141_环形链表 {

    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) return false;
        ListNode slow = head;
        ListNode fast = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow= slow.next;

            if(slow == fast) return true;
        }
        return false;
    }
}
